{% extends "risk/risk_base.html" %}
{% block title %}贷款跟进{% endblock %}
{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-table.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}">
{% endblock %}
{% block page_content %}

<h1 class="page-header">贷款跟进</h1>
{{ super() }}
<div class="col-md-12">
    <div class="panel-body" style="padding-bottom:0px;">
        <ul id="myTab" class="nav nav-tabs">
            <li class="active">
                <a href="#to_launch" data-toggle="tab" onclick="setTable('to_launch')">待发起</a>
            </li>
            <li>
                <a href="#active" data-toggle="tab" onclick="setTable('active')">生效</a>
            </li>
            <li>
                <a href="#expired" data-toggle="tab" onclick="setTable('expired')">逾期</a>
            </li>
            <li>
                <a href="#pay_off" data-toggle="tab" onclick="setTable('pay_off')">已还清</a>
            </li>
        </ul>
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade in active" id="to_launch">
                <table id="tb_to_launch"></table>
            </div>
            <div class="tab-pane fade" id="active">
                <table id="tb_active"></table>
            </div>
            <div class="tab-pane fade" id="expired">
                <table id="tb_expired"></table>
            </div>
            <div class="tab-pane fade" id="pay_off">
                <table id="tb_pay_off"></table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block scripts  %}
{{ super() }}
<script src="{{ url_for('static', filename='js/bootstrap-table.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-table-zh-CN.min.js') }}"></script>
<script>
$(function () {

    //初始化Table
    var tb_to_launch = new TableInit("tb_to_launch");
    tb_to_launch.Init();
    var tb_active = new TableInit("tb_active");
    tb_active.Init();
    var tb_active = new TableInit("tb_expired");
    tb_active.Init();
    var tb_active = new TableInit("tb_pay_off");
    tb_active.Init();
});


var TableInit = function (table_id) {
    var oTableInit = new Object();
    var urls = new Array();
    urls['tb_to_launch'] = "/risk/loan_track/get_list?list_type=to_launch";
    urls['tb_active'] = "/risk/loan_track/get_list?list_type=active";
    urls['tb_expired'] = "/risk/loan_track/get_list?list_type=expired";
    urls['tb_pay_off'] = "/risk/loan_track/get_list?list_type=pay_off";

    var name = new Array();
    name['tb_to_launch'] = "放款通过日期";
    name['tb_active'] = "到期日期";
    name['tb_expired'] = "到期日期";
    name['tb_pay_off'] = "还清日期";


    //初始化Table
    table = document.getElementById(table_id);
    oTableInit.Init = function () {
        $(table).bootstrapTable({
            url: urls[table_id],                //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber:1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showRefresh: true,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'flow_id',
                    title: 'ID',
                    align: 'center',
                },
                {
                    field: 'pledge_type',
                    title: '贷款类型',
                    align: 'center',
                },
                {
                    field: 'amount',
                    title: '金额(元)',
                    align: 'center',
                },
                {
                    field: 'days',
                    title: '期限(天)',
                    align: 'center',
                },
                {
                    field: 'area',
                    title: '申请地区',
                    align: 'center',
                },
                {
                    field: 'name',
                    title: '贷款人',
                    align: 'center',
                },
                {
                    field: 'track_number',
                    title: '跟进人',
                    align: 'center',
                },
                {
                    field: 'loan_status',
                    title: '贷款状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.loan_status === '即将到期') {
                            return '<p style="color: red;">' + row.loan_status + '</p>'
                        } else {
                            return row.loan_status
                        }
                    }
                },
                {
                    field: 'term',
                    title: '当前期数/总期数',
                    align: 'center',
                    visible: table_id === 'tb_active',
                },
                {
                    field: 'date_description',
                    title: name[table_id],
                    align: 'center',
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    // events: operateEvents,
                    formatter: function (value, row, index) {
                        var name = new Array();
                        name['tb_to_launch'] = "发起跟进";
                        name['tb_active'] = "跟进";
                        name['tb_expired'] = "查看";
                        name['tb_pay_off'] = "查看"; 

                        if (table_id === 'tb_to_launch') {
                            return [
                            '<a class="" href="/risk/loan_track/launch/' + row.flow_id + '" >',
                            name[table_id],
                            '</a>'
                            ].join('');
                        } else {
                            return [
                            '<a class="" href="/risk/loan_track/record/' + row.flow_id + '" >',
                            name[table_id],
                            '</a>'
                            ].join('');                            
                        }

                    }
                },
            ]
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
        var temp = { 
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                number: $("#number").val(),
                start: $("#start").val(),
                end: $("#end").val(),
                submitter: $("#submitter").val(),
                area: $("#area").val(),
                search_type: $("#search_type").val(),
                tb_name: $("#tb_name").val(),
            };
        return temp;
    };

    return oTableInit;
};
var selected_table = 'to_launch';

var setTable = function(table){
    selected_table = table;
}

var search = function(){
    document.getElementById('tb_name').value = selected_table;
    $('#tb_' + selected_table).bootstrapTable('refresh', {'silent': true});
}

function operateFormatter(value, row, index) {
  
    return '<a class="" href="/risk/application/detail/' + row.id + '" title="审核">';
           
};
window.operateEvents = {

}


</script>
<script>
    nav = document.getElementById("nav_loan_track");
    nav.setAttribute("class", "active");

</script>
{% endblock %}
